package com.account.book.controller;


import com.account.book.common.context.UserTokenContextHolder;
import com.account.book.common.response.BaseResult;
import com.account.book.common.response.ResultUtils;
import com.account.book.request.UpdateUserInfo;
import com.account.book.request.UserLoginReqVo;
import com.account.book.request.UserNameReqVo;
import com.account.book.response.UserLoginRespVo;
import com.account.book.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author liang-hw
 * @className UserController
 * @description用户表（微信）表 前端控制器
 * @date 2023/11/08 11:38:29
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * @param @param reqVo
     * @return @return {@link UserLoginRespVo }
     * @author liang-hw
     * @description 用户登录
     * @date 2023/11/08 11:40:50
     */
    @ApiOperation(value = "用户登录", notes = "用户登录")
    @PostMapping("/login")
    public BaseResult<UserLoginRespVo> login(@RequestBody UserLoginReqVo reqVo) {
        return ResultUtils.success(userService.userLogin(reqVo));
    }

    @ApiOperation(value = "修改用户昵称，头像", notes = "修改用户昵称，头像")
    @PostMapping("/updateUserInfo")
    public BaseResult<UserLoginRespVo> updateUserInfo(@Valid @RequestBody UpdateUserInfo UpdateUserInfo) {
        String userId=UserTokenContextHolder.getUserTokenVOByToken().getUserId();
        UserLoginRespVo userLoginRespVO = userService.updateUserInfo(UpdateUserInfo,userId);
        return ResultUtils.success(userLoginRespVO);
    }

    /**
     * @param @param userNameReqVo
     * @return
     * @author liang-hw
     * @description 修改用户别名，真实姓名
     * @date 2023/11/08 11:41:02
     */
    @ApiOperation(value = "修改用户别名，真实姓名", notes = "修改用户别名，真实姓名")
    @PostMapping("/updateReallyNameAndUserName")
    public BaseResult updateReallyNameAndUserName(@Valid @RequestBody UserNameReqVo userNameReqVo) {
        userService.updateReallyNameAndUserName(userNameReqVo);
        return ResultUtils.success();
    }
}
